package com.pdg.android.rockscissorspaper;

import android.app.Activity;
import android.content.SharedPreferences;

public class Settings {
	private static final String PREFERENCES_NAME = "RSP_SHAREDPREFS";
	private static final String ROUNDS_FIXED = "ROUNDS_FIXED";
	private static final Boolean ROUNDS_FIXED_DEFAULT = true;
	private static final String ROUND_COUNT = "ROUND_COUNT";
	private static final Integer ROUND_COUNT_DEFAULT = 5;
	
	private static final String ROCK_WINS = "ROCK_WINS";
	private static final String ROCK_TIES = "ROCK_TIES";
	private static final String ROCK_LOSSES = "ROCK_LOSSES";
	private static final String SCISSORS_WINS = "SCISSORS_WINS";
	private static final String SCISSORS_TIES = "SCISSORS_TIES";
	private static final String SCISSORS_LOSSES = "SCISSORS_LOSSES";
	private static final String PAPER_WINS = "PAPER_WINS";
	private static final String PAPER_TIES = "PAPER_TIES";
	private static final String PAPER_LOSSES = "PAPER_LOSSES";
	private static final String MATCH_WINS = "MATCH_WINS";
	private static final String MATCH_LOSSES = "MATCH_LOSSES";
	private static final Integer WINS_TIES_LOSSES_DEFAULT = 0;
	
	private static final String ROUND_NUMBER = "ROUND_NUMBER";
	public static final Integer ROUND_NUMBER_DEFAULT = 1;
	public static final String HUMAN_SCORE = "HUMAN_SCORE";
	public static final Integer HUMAN_SCORE_DEFAULT = 0;
	public static final String COMPUTER_SCORE="COMPUTER_SCORE";
	public static final Integer COMPUTER_SCORE_DEFAULT = 0;
	
	
	
	private static boolean getBooleanPreference(Activity theActivity,String thePreferenceName,Boolean theDefault){
		SharedPreferences thePrefs = theActivity.getSharedPreferences(PREFERENCES_NAME, 0);
		return thePrefs.getBoolean(thePreferenceName, theDefault);
	}
	private static int getIntPreference(Activity theActivity,String thePreferenceName,int theDefault){
		SharedPreferences thePrefs = theActivity.getSharedPreferences(PREFERENCES_NAME, 0);
		return thePrefs.getInt(thePreferenceName, theDefault);
	}
	private static void setBooleanPreference(Activity theActivity,String thePreferenceName,Boolean theValue){
		SharedPreferences thePrefs = theActivity.getSharedPreferences(PREFERENCES_NAME, 0);
		SharedPreferences.Editor theEditor = thePrefs.edit();
		theEditor.putBoolean(thePreferenceName, theValue);
		theEditor.commit();
	}
	private static void setIntPreference(Activity theActivity,String thePreferenceName,Integer theValue){
		SharedPreferences thePrefs = theActivity.getSharedPreferences(PREFERENCES_NAME, 0);
		SharedPreferences.Editor theEditor = thePrefs.edit();
		theEditor.putInt(thePreferenceName, theValue);
		theEditor.commit();
	}
	public static boolean getRoundsFixed(Activity theActivity){
		return getBooleanPreference(theActivity,ROUNDS_FIXED, ROUNDS_FIXED_DEFAULT);
	}
	public static int getRoundCount(Activity theActivity){
		return getIntPreference(theActivity,ROUND_COUNT, ROUND_COUNT_DEFAULT);
	}
	public static void setRoundsFixed(Activity theActivity,boolean theRoundsFixed){
		setBooleanPreference(theActivity,ROUNDS_FIXED, theRoundsFixed);
	}
	public static void setRoundCount(Activity theActivity,int theRoundCount){
		setIntPreference(theActivity,ROUND_COUNT, theRoundCount);
	}

	public static void setNumberOfRockWins(Activity theActivity,int theCount){
		setIntPreference(theActivity,ROCK_WINS,theCount);
		
	}
	public static void setNumberOfRockTies(Activity theActivity,int theCount){
		setIntPreference(theActivity,ROCK_TIES,theCount);
	}
	public static void setNumberOfRockLosses(Activity theActivity,int theCount){
		setIntPreference(theActivity,ROCK_LOSSES,theCount);
	}
	public static void setNumberOfScissorsWins(Activity theActivity,int theCount){
		setIntPreference(theActivity,SCISSORS_WINS,theCount);
	}
	public static void setNumberOfScissorsTies(Activity theActivity,int theCount){
		setIntPreference(theActivity,SCISSORS_TIES,theCount);
	}
	public static void setNumberOfScissorsLosses(Activity theActivity,int theCount){
		setIntPreference(theActivity,SCISSORS_LOSSES,theCount);
	}
	public static void setNumberOfPaperWins(Activity theActivity,int theCount){
		setIntPreference(theActivity,PAPER_WINS,theCount);
	}
	public static void setNumberOfPaperTies(Activity theActivity,int theCount){
		setIntPreference(theActivity,PAPER_TIES,theCount);
	}
	public static void setNumberOfPaperLosses(Activity theActivity,int theCount){
		setIntPreference(theActivity,PAPER_LOSSES,theCount);
	}
	public static void setNumberOfMatchWins(Activity theActivity,int theCount){
		setIntPreference(theActivity,MATCH_WINS,theCount);
	}
	public static void setNumberOfMatchLosses(Activity theActivity,int theCount){
		setIntPreference(theActivity,MATCH_LOSSES,theCount);
	}
	public static void setRoundNumber(Activity theActivity,int theNumber){
		setIntPreference(theActivity,ROUND_NUMBER,theNumber);
	}
	public static void resetStatistics(Activity theActivity){
		setNumberOfMatchWins(theActivity,WINS_TIES_LOSSES_DEFAULT);
		setNumberOfMatchLosses(theActivity,WINS_TIES_LOSSES_DEFAULT);
		setNumberOfRockWins(theActivity,WINS_TIES_LOSSES_DEFAULT);
		setNumberOfRockTies(theActivity,WINS_TIES_LOSSES_DEFAULT);
		setNumberOfRockLosses(theActivity,WINS_TIES_LOSSES_DEFAULT);
		setNumberOfScissorsWins(theActivity,WINS_TIES_LOSSES_DEFAULT);
		setNumberOfScissorsTies(theActivity,WINS_TIES_LOSSES_DEFAULT);
		setNumberOfScissorsLosses(theActivity,WINS_TIES_LOSSES_DEFAULT);
		setNumberOfPaperWins(theActivity,WINS_TIES_LOSSES_DEFAULT);
		setNumberOfPaperTies(theActivity,WINS_TIES_LOSSES_DEFAULT);
		setNumberOfPaperLosses(theActivity,WINS_TIES_LOSSES_DEFAULT);

	}
	public static int getNumberOfRockWins(Activity theActivity){
		return getIntPreference(theActivity,ROCK_WINS,WINS_TIES_LOSSES_DEFAULT);
	}
	public static int getNumberOfRockTies(Activity theActivity){
		return getIntPreference(theActivity,ROCK_TIES,WINS_TIES_LOSSES_DEFAULT);
	}
	public static int getNumberOfRockLosses(Activity theActivity){
		return getIntPreference(theActivity,ROCK_LOSSES,WINS_TIES_LOSSES_DEFAULT);
	}
	public static int getNumberOfScissorsWins(Activity theActivity){
		return getIntPreference(theActivity,SCISSORS_WINS,WINS_TIES_LOSSES_DEFAULT);
	}
	public static int getNumberOfScissorsTies(Activity theActivity){
		return getIntPreference(theActivity,SCISSORS_TIES,WINS_TIES_LOSSES_DEFAULT);
	}
	public static int getNumberOfScissorsLosses(Activity theActivity){
		return getIntPreference(theActivity,SCISSORS_LOSSES,WINS_TIES_LOSSES_DEFAULT);
	}
	public static int getNumberOfPaperWins(Activity theActivity){
		return getIntPreference(theActivity,PAPER_WINS,WINS_TIES_LOSSES_DEFAULT);
	}
	public static int getNumberOfPaperTies(Activity theActivity){
		return getIntPreference(theActivity,PAPER_TIES,WINS_TIES_LOSSES_DEFAULT);
	}
	public static int getNumberOfPaperLosses(Activity theActivity){
		return getIntPreference(theActivity,PAPER_LOSSES,WINS_TIES_LOSSES_DEFAULT);
	}
	public static int getNumberOfMatchWins(Activity theActivity){
		return getIntPreference(theActivity,MATCH_WINS,WINS_TIES_LOSSES_DEFAULT);
	}
	public static int getNumberOfMatchLosses(Activity theActivity){
		return getIntPreference(theActivity,MATCH_LOSSES,WINS_TIES_LOSSES_DEFAULT);
	}
	public static int getNumberOfRockPlays(Activity theActivity){
		return getNumberOfRockWins(theActivity) + getNumberOfRockTies(theActivity)+getNumberOfRockLosses(theActivity);
	}
	public static int getNumberOfScissorsPlays(Activity theActivity){
		return getNumberOfScissorsWins(theActivity) + getNumberOfScissorsTies(theActivity)+getNumberOfScissorsLosses(theActivity);
	}
	public static int getNumberOfPaperPlays(Activity theActivity){
		return getNumberOfPaperWins(theActivity) + getNumberOfPaperTies(theActivity)+getNumberOfPaperLosses(theActivity);
	}
	public static int getNumberOfMatches(Activity theActivity){
		return getNumberOfMatchWins(theActivity) + getNumberOfMatchLosses(theActivity);
	}
	public static int getRoundNumber(Activity theActivity){
		return getIntPreference(theActivity,ROUND_NUMBER,ROUND_NUMBER_DEFAULT);
	}
	public static int getHumanScore(Activity theActivity){
		return getIntPreference(theActivity,HUMAN_SCORE,HUMAN_SCORE_DEFAULT);
	}
	public static int getComputerScore(Activity theActivity){
		return getIntPreference(theActivity,COMPUTER_SCORE,COMPUTER_SCORE_DEFAULT);
	}
	public static void setHumanScore(Activity theActivity,int theScore){
		setIntPreference(theActivity,HUMAN_SCORE,theScore);
	}
	public static void setComputerScore(Activity theActivity,int theScore){
		setIntPreference(theActivity,COMPUTER_SCORE,theScore);
	}
}
